<!DOCTYPE html><html lang="zh-CN"><head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width">
  <title>utcOffset() | Moment.js &#x6587;&#x6863;</title>
  <link rel="stylesheet" href="static/css/style.css">
  <link rel="shortcut icon" href="http://momentjs.cn/static/img/moment-favicon.png">
  <link rel="stylesheet" href="static/css/atom-one-light.min.css">
</head>
<body class="is-moment">
  <div class="hero hero-oneline">
    <div class="hero-centered">
      <h1>utcOffset()</h1>
    </div>
  </div>
  <div id="api-section-__FILENAME__">
    <div id="content" class="clearfix">
  
      <div id="column1" data-id="__ID__" class="interior">
        <header>
          <!-- <h1>utcOffset()</h1> -->
          <div id="gtoc">
            <ul>
              <!-- <li>v</li> -->
              <li>
                <a href="index.html#/manipulating/utc-offset/" name="toc">&#x8FD4;&#x56DE;&#x4E0A;&#x5C42;&#x6587;&#x6863;</a>
              </li>
              <li style="border: none;">
                <a href="javascript:window.open('https://github.com/momentjscn/moment-docs-cn/edit/master/moment/03-manipulating/09-utc-offset.md');" rel="nofollow" target="_blank">&#x63D0;&#x4EA4;&#x4FEE;&#x6539;</a>
              </li>
              <!-- <li>
                <a href="/search__SEARCH_PARAM__" name="toc">搜索</a>
              </li> -->
            </ul>
          </div>
          <hr>
        </header>

        <div id="biz_item"></div>
  
        <div id="apicontent">
          <div id="content_left">
							<div class="docs-method-signature">
								<pre><code class="language-js">moment().utcOffset();
moment().utcOffset(Number|String);
moment().utcOffset(Number|String, Boolean);
</code></pre>

							</div>
<p>&#x83B7;&#x53D6; UTC &#x504F;&#x79FB;&#x91CF;&#xFF08;&#x4EE5;&#x5206;&#x949F;&#x4E3A;&#x5355;&#x4F4D;&#xFF09;&#x3002;</p>
<p>&#x6CE8;&#x610F;&#xFF1A;&#x4E0E; <a href="javascript:window.open('http://nodejs.cn/s/sA3jtZ');" target="_blank" rel="nofollow"><code>moment.fn.zone</code></a> &#x4E0D;&#x540C;&#xFF0C;&#x6B64;&#x51FD;&#x6570;&#x8FD4;&#x56DE; UTC &#x7684;&#x5B9E;&#x9645;&#x504F;&#x79FB;&#x91CF;&#xFF0C;&#x800C;&#x4E0D;&#x662F;&#x53CD;&#x5411;&#x504F;&#x79FB;&#x91CF;&#xFF08;&#x7C7B;&#x4F3C; <code>Date.prototype.getTimezoneOffset</code> &#x8FD4;&#x56DE;&#x7684;&#xFF09;&#x3002;</p>
<p>&#x83B7;&#x53D6;&#x5F53;&#x524D;&#x5BF9;&#x8C61;&#x7684; <code>utcOffset</code>&#xFF1A;</p>
<pre><code class="language-javascript">moment().utcOffset(); // (-240&#x3001;-120&#x3001;-60&#x3001;0&#x3001;60&#x3001;120&#x3001;240 &#x7B49;)
</code></pre>
<p>&#x901A;&#x8FC7;&#x63D0;&#x4F9B;&#x5206;&#x949F;&#x6570;&#x6765;&#x8BBE;&#x7F6E; UTC &#x504F;&#x79FB;&#x91CF;&#x3002;
&#x5728;&#x8C03;&#x7528; <code>utcOffset()</code> &#x7684; moment &#x5BF9;&#x8C61;&#x4E0A;&#x8BBE;&#x7F6E;&#x504F;&#x79FB;&#x91CF;&#x3002;
&#x5982;&#x679C;&#x60F3;&#x8981;&#x5168;&#x5C40;&#x5730;&#x8BBE;&#x7F6E;&#x504F;&#x79FB;&#x91CF;&#xFF0C;&#x5219;&#x5C1D;&#x8BD5;&#x4F7F;&#x7528; <a href="javascript:window.open('http://nodejs.cn/s/NnazvZ');" target="_blank" rel="nofollow">moment-timezone</a>&#x3002;
&#x6CE8;&#x610F;&#xFF0C;&#x4E00;&#x65E6;&#x8BBE;&#x7F6E;&#x4E86;&#x504F;&#x79FB;&#x91CF;&#xFF0C;&#x5219;&#x5B83;&#x4FBF;&#x4F1A;&#x56FA;&#x5B9A;&#x4E14;&#x4E0D;&#x4F1A;&#x5355;&#x72EC;&#x66F4;&#x6539;&#xFF08;&#x5373;&#x6CA1;&#x6709; DST &#x89C4;&#x5219;&#xFF09;&#x3002;
&#x5982;&#x679C;&#x60F3;&#x8981;&#x4E00;&#x4E2A;&#x5B9E;&#x9645;&#x7684;&#x65F6;&#x533A;&#xFF08;&#x7279;&#x5B9A;&#x4F4D;&#x7F6E;&#x7684;&#x65F6;&#x95F4;&#xFF09;&#xFF0C;&#x4F8B;&#x5982; <code>America/Los_Angeles</code>&#xFF0C;&#x5219;&#x8003;&#x8651;&#x4F7F;&#x7528; <a href="javascript:window.open('http://nodejs.cn/s/NnazvZ');" target="_blank" rel="nofollow">moment-timezone</a>&#x3002;</p>
<pre><code class="language-javascript">moment().utcOffset(120);
</code></pre>
<p>&#x5982;&#x679C;&#x8F93;&#x5165;&#x5C0F;&#x4E8E; <code>16</code> &#x4E14;&#x5927;&#x4E8E; <code>-16</code>&#xFF0C;&#x5219;&#x4F1A;&#x5C06;&#x8F93;&#x5165;&#x89E3;&#x91CA;&#x4E3A;&#x5C0F;&#x65F6;&#x3002;</p>
<pre><code class="language-javascript">// &#x8FD9;&#x4E9B;&#x662F;&#x7B49;&#x6548;&#x7684;&#x3002;
moment().utcOffset(8);  // &#x8BBE;&#x7F6E;&#x5C0F;&#x65F6;&#x504F;&#x79FB;
moment().utcOffset(480);  // &#x8BBE;&#x7F6E;&#x5206;&#x949F;&#x504F;&#x79FB; (8 * 60)
</code></pre>
<p>&#x4E5F;&#x53EF;&#x4EE5;&#x8BBE;&#x7F6E;&#x5B57;&#x7B26;&#x4E32;&#x7684; UTC &#x504F;&#x79FB;&#x91CF;&#x3002;</p>
<pre><code class="language-javascript">// &#x8FD9;&#x4E9B;&#x662F;&#x7B49;&#x6548;&#x7684;&#x3002;
moment().utcOffset(&quot;+08:00&quot;);
moment().utcOffset(8);
moment().utcOffset(480);
</code></pre>
<p><code>moment#utcOffset</code> &#x4F1A;&#x5728;&#x5B57;&#x7B26;&#x4E32;&#x4E2D;&#x641C;&#x7D22; <code>+00:00 +0000 -00:00 -0000 Z</code> &#x7684;&#x7B2C;&#x4E00;&#x4E2A;&#x5339;&#x914D;&#x9879;&#xFF0C;&#x56E0;&#x6B64;&#x751A;&#x81F3;&#x53EF;&#x4EE5;&#x4F20;&#x5165; ISO8601 &#x683C;&#x5F0F;&#x7684;&#x5B57;&#x7B26;&#x4E32;&#xFF0C;&#x4E14; moment &#x5C06;&#x4F1A;&#x66F4;&#x6539;&#x4E3A; UTC &#x504F;&#x79FB;&#x91CF;&#x3002;</p>
<p>&#x6CE8;&#x610F;&#xFF0C;&#x5982;&#x679C;&#x5B57;&#x7B26;&#x4E32;&#x4E0D;&#x662F; &apos;Z&apos;&#xFF0C;&#x5219;&#x5FC5;&#x987B;&#x4EE5; <code>+</code> &#x6216; <code>-</code> &#x5B57;&#x7B26;&#x5F00;&#x5934;&#x3002;</p>
<pre><code class="language-javascript">moment().utcOffset(&quot;2013-03-07T07:00:00+08:00&quot;);
</code></pre>
<p><code>utcOffset</code> &#x51FD;&#x6570;&#x5177;&#x6709;&#x53EF;&#x9009;&#x7684;&#x7B2C;&#x4E8C;&#x4E2A;&#x53C2;&#x6570;&#xFF0C;&#x8BE5;&#x53C2;&#x6570;&#x63A5;&#x53D7;&#x4E00;&#x4E2A;&#x5E03;&#x5C14;&#x503C;&#xFF0C;&#x8BE5;&#x5E03;&#x5C14;&#x503C;&#x8868;&#x660E;&#x662F;&#x5426;&#x4FDD;&#x7559;&#x65E5;&#x671F;&#x4E2D;&#x7684;&#x73B0;&#x6709;&#x65F6;&#x95F4;&#x3002;</p>
<ul>
<li><p>&#x4F20;&#x5165; <code>false</code>&#xFF08;&#x9ED8;&#x8BA4;&#xFF09;&#x5C06;&#x4F1A;&#x5728;&#x4E16;&#x754C;&#x6807;&#x51C6;&#x65F6;&#x95F4;&#x4E2D;&#x4FDD;&#x6301;&#x4E0D;&#x53D8;&#xFF0C;&#x4F46;&#x672C;&#x5730;&#x65F6;&#x95F4;&#x5C06;&#x4F1A;&#x6539;&#x53D8;&#x3002;</p></li>
<li><p>&#x4F20;&#x5165; <code>true</code> &#x5C06;&#x4FDD;&#x7559;&#x76F8;&#x540C;&#x7684;&#x672C;&#x5730;&#x65F6;&#x95F4;&#xFF0C;&#x4F46;&#x8981;&#x4EE5;&#x5728;&#x4E16;&#x754C;&#x6807;&#x51C6;&#x65F6;&#x95F4;&#x4E2D;&#x9009;&#x62E9;&#x5176;&#x4ED6;&#x65F6;&#x95F4;&#x4E3A;&#x4EE3;&#x4EF7;&#x3002;</p></li>
</ul>
<p>&#x6B64;&#x7279;&#x6027;&#x7684;&#x4E00;&#x79CD;&#x7528;&#x6CD5;&#x662F;&#xFF0C;&#x5982;&#x679C;&#x53EA;&#x60F3;&#x4F7F;&#x7528;&#x6570;&#x5B57;&#x578B;&#x8F93;&#x5165;&#x503C;&#x6765;&#x6784;&#x9020;&#x5177;&#x6709;&#x7279;&#x5B9A;&#x65F6;&#x533A;&#x504F;&#x79FB;&#x91CF;&#x7684; moment&#xFF1A;</p>
<pre><code class="language-javascript">moment([2016, 0, 1, 0, 0, 0]).utcOffset(-5, true) // &#x7B49;&#x6548;&#x4E8E; &quot;2016-01-01T00:00:00-05:00&quot;
</code></pre>
					</div>
          <div id="content_right">
							<div class="docs-method-signature">
								<pre><code class="language-js">moment().utcOffset();
moment().utcOffset(Number|String);
moment().utcOffset(Number|String, Boolean);
</code></pre>

							</div>
<p>Get the UTC offset in minutes.</p>
<p><strong>Note:</strong> Unlike <a href="index.html#/manipulating/timezone-offset/" target="_blank" rel="nofollow"><code>moment.fn.zone</code></a> this
function returns the real offset from UTC, not the reverse offset (as returned
by <code>Date.prototype.getTimezoneOffset</code>).</p>
<p>Getting the <code>utcOffset</code> of the current object:</p>
<pre><code class="language-javascript">moment().utcOffset(); // (-240, -120, -60, 0, 60, 120, 240, etc.)
</code></pre>
<p>Setting the UTC offset by supplying minutes. The offset is set on the moment object
that <code>utcOffset()</code> is called on. If you are wanting to set the offset globally,
try using <a href="index2.html" target="_blank" rel="nofollow">moment-timezone</a>. Note that once you set an offset,
it&apos;s fixed and won&apos;t change on its own (i.e there are no DST rules). If you want
an actual time zone -- time in a particular location, like
<code>America/Los_Angeles</code>, consider <a href="index2.html" target="_blank" rel="nofollow">moment-timezone</a>.</p>
<pre><code class="language-javascript">moment().utcOffset(120);
</code></pre>
<p>If the input is less than <code>16</code> and greater than <code>-16</code>, it will interpret your input as hours instead.</p>
<pre><code class="language-javascript">// these are equivalent
moment().utcOffset(8);  // set hours offset
moment().utcOffset(480);  // set minutes offset (8 * 60)
</code></pre>
<p>It is also possible to set the UTC offset from a string.</p>
<pre><code class="language-javascript">// these are equivalent
moment().utcOffset(&quot;+08:00&quot;);
moment().utcOffset(8);
moment().utcOffset(480);
</code></pre>
<p><code>moment#utcOffset</code> will search the string for the first match of <code>+00:00 +0000 -00:00 -0000 Z</code>, so you can even pass an ISO8601 formatted string and the moment
will be changed to that UTC offset.</p>
<p>Note that the string, if not &apos;Z&apos;, is required to start with the <code>+</code> or <code>-</code> character.</p>
<pre><code class="language-javascript">moment().utcOffset(&quot;2013-03-07T07:00:00+08:00&quot;);
</code></pre>
<p>The <code>utcOffset</code> function has an optional second parameter which accepts a boolean value
indicating whether to keep the existing time of day.</p>
<ul>
<li><p>Passing <code>false</code> (the default) will keep the same instant in Universal Time, but the
local time will change.</p></li>
<li><p>Passing <code>true</code> will keep the same local time, but at the expense of choosing a different
point in Universal Time.</p></li>
</ul>
<p>One use of this feature is if you want to construct a moment with a specific time zone
offset using only numeric input values:</p>
<pre><code class="language-javascript">moment([2016, 0, 1, 0, 0, 0]).utcOffset(-5, true) // Equivalent to &quot;2016-01-01T00:00:00-05:00&quot;
</code></pre>
					</div>
          <div></div>
        </div>
      </div>
    </div>
  </div>
  
  <script src="static/js/highlight.min.js"></script>
  <script src="static/js/javascript.min.js"></script>
  <script>hljs.initHighlightingOnLoad();</script>
  <script>var _hmt = _hmt || []; (function () { var hm = document.createElement("script"); hm.src = "//hm.baidu.com/hm.js?7a7f78c805fbacc7e075d34f153031aa"; var s = document.getElementsByTagName("script")[0]; s.parentNode.insertBefore(hm, s); })();</script>

  <style>
    .hero-centered {
      margin: 0;
          margin-left: 10px;
    }
#gtoc ul {
  list-style: none;
  margin-left: 0;
  line-height: 1.5rem;
  padding: 0;
}
#gtoc>ul>li {
  display: inline;
  border-right: 1px solid #000;
  margin-right: .4rem;
  padding-right: .4rem;
}
#gtoc>ul>li>a {
  color: #61b2a7;
}
#content_left {
  width: 49%;float: left;border-right: 1px solid #eee;    padding-right: 2%;
}
#content_right {
float: left;width: 48%;margin-left: 3%;
}
#column1 {
  padding: 0 2rem;
}
  </style>


</body></html>